from files.models import *
def printing_data():
    id_list = TbPrinting.objects.values_list("drawing_file_id").distinct()

    for file_id in id_list:
        if TbDrawingFile.objects.filter(id=file_id[0]):
            drawing = TbDrawingFile.objects.filter(id=file_id[0]).values_list(
                "drawing_type__cutter__type__cutter_type",
                "drawing_type__cutter__product_stage")[0]

        else:
            drawing=[None,None]
        TbPrinting.objects.filter(drawing_file_id=file_id[0]).update(product_type=drawing[0],product_stage=drawing[1])
    return True

def despense_data():
    id_list = TbDepense.objects.values_list("drawing_file_id",flat=1).distinct()
    for file_id in id_list:
        if TbDrawingFile.objects.filter(id=file_id):
            drawing = TbDrawingFile.objects.filter(id=file_id).values_list(
                "drawing_type__cutter__type__cutter_type",
                "drawing_type__cutter__product_stage")[0]
        else:
            continue
        TbDepense.objects.filter(drawing_file_id=file_id).update(product_type=drawing[0],product_stage=drawing[1])
